import { ModalForm } from '@ant-design/pro-form';
import { Button, message } from 'antd';
import React from 'react';

import { IMenu } from '@/models/user';
import { updateMenus } from '@/services/system/menu';

import MenuForm from './components/MenuForm';
import type { menuProps } from './type';

const UpdateMenu: React.FC<menuProps> = ({ menus, onReload }) => {
  return (
    <ModalForm<IMenu>
      title="编辑菜单"
      trigger={<Button type="link">编辑</Button>}
      modalProps={{
        keyboard: false,
        maskClosable: false,
        onCancel: () => console.log('run'),
      }}
      onFinish={async (values) => {
        await updateMenus(values);
        message.success('提交成功');
        onReload && onReload();
        return true;
      }}>
      <MenuForm menus={menus} />
    </ModalForm>
  );
};

export default UpdateMenu;
